package com.tul.vapp.servicecenter.controller;

import com.tul.vapp.servicecenter.bean.EmsConfig;
import com.tul.vapp.servicecenter.bean.ResponseBean;
import com.tul.vapp.servicecenter.service.IEmsProxyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * EmsProxy配置管理
 *
 * @author wwxiang
 * @since 2018/1/16.
 */
@RestController
public class EmsProxyController {

    /**
     * itemService
     */
    @Autowired
    private IEmsProxyService emsProxyService;

    /**
     * getEmsConfig
     *
     * @return ems配置
     */
    @RequestMapping(value = "/getEmsConfig")
    public ResponseBean getEmsConfig() {
        List<EmsConfig> configs = emsProxyService.getEmsConfigs();
        ResponseBean bean = new ResponseBean();
        bean.setData(configs);
        return bean;
    }

    /**
     * updateEmsConfig
     *
     * @param emsConfig ems配置
     * @return 结果
     */
    @RequestMapping(value = "/updateEmsConfig")
    public ResponseBean updateEmsConfig(@RequestBody EmsConfig emsConfig) {
        ResponseBean bean = new ResponseBean();
        bean.setSuccess(emsProxyService.updateEmsConfig(emsConfig));
        return bean;
    }

    /**
     * addEmsConfig
     *
     * @param emsConfig ems配置
     * @return 结果
     */
    @RequestMapping(value = "/addEmsConfig")
    public ResponseBean addEmsConfig(@RequestBody EmsConfig emsConfig) {
        ResponseBean bean = new ResponseBean();
        bean.setSuccess(emsProxyService.addEmsConfig(emsConfig));
        return bean;
    }

    /**
     * deleteEmsConfig
     *
     * @param params emsId
     * @return 结果
     */
    @RequestMapping(value = "/deleteEmsConfig")
    public ResponseBean deleteEmsConfig(@RequestBody Map<String, Integer> params) {
        ResponseBean bean = new ResponseBean();
        int emsId = params.get("emsId");
        bean.setSuccess(emsProxyService.deleteEmsConfig(emsId));
        return bean;
    }

    /**
     * addEmsConfig
     *
     * @param params emsId
     * @return 结果
     */
    @RequestMapping(value = "/syncEms")
    public ResponseBean syncEms(@RequestBody Map<String, Integer> params) {
        ResponseBean bean = new ResponseBean();
        int emsId = params.get("emsId");
        bean.setSuccess(emsProxyService.syncEms(emsId));
        return bean;
    }

    /**
     * 发布ems
     *
     * @return 结果
     */
    @RequestMapping(value = "/publishEms")
    public ResponseBean publishEms() {
        ResponseBean bean = new ResponseBean();
        bean.setSuccess(emsProxyService.publishEms());
        return bean;
    }

}
